package com.omt.tarjimdinek.domain.user.Service;

import java.util.UUID;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import org.apache.log4j.Logger;
import org.springframework.transaction.annotation.Transactional;

import com.omt.tarjimdinek.domain.user.dao.ValidationMembreCriteria;
import com.omt.tarjimdinek.domain.user.dao.ValidationMembreDao;
import com.omt.tarjimdinek.domain.user.entity.ValidationMembre;
import com.omt.tarjimdinek.support.GenericDao;
import com.omt.tarjimdinek.support.RepositoryImpl;

/**
 * validation member manager implements
 * @author chabane
 *
 */
@Named("validationMembreRepository")
@Singleton
public class ValidationMembreRepositoryImpl extends RepositoryImpl<ValidationMembre, Long> implements ValidationMembreRepository {

	private ValidationMembreDao validationMembreDao; 
	
	@SuppressWarnings("unused")
	private static final Logger log = Logger.getLogger(ValidationMembreRepositoryImpl.class);

	@Inject
	public void setValidationMembreDao(ValidationMembreDao validationMembreDao) {
	   this.validationMembreDao = validationMembreDao;
	}

	/**
	  * Dao getter used by the {@link RepositoryImpl}.
	  */
	@Override
	public GenericDao<ValidationMembre, Long> getDao() {
	   return validationMembreDao;
	}     

	/**
     * {@inheritDoc}
     */
    @Override
    public ValidationMembre getNew() {
        return new ValidationMembre();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ValidationMembre getNewWithDefaults() {
    	ValidationMembre result = getNew();
        result.initDefaultValues();
        return result;
    }

    /**
     * {@inheritDoc}
     */
	@Override
	@Transactional
	public ValidationMembre createValidationMembre(String aEmail, String aTypeValidation) {
		ValidationMembre lValidationMembre = getNew();
		lValidationMembre.setUuid(UUID.randomUUID().toString());
		lValidationMembre.setEmail(aEmail);
		lValidationMembre.setTypeValidation(aTypeValidation);
		lValidationMembre.setValidated(Boolean.FALSE);
		save(lValidationMembre);
		return lValidationMembre;
	}
	
	/**
     * {@inheritDoc}
     */
	@Override
	@Transactional
	public ValidationMembre findValidationMembre(String aUuid, String aEmail) {
		ValidationMembreCriteria lCriteria = new ValidationMembreCriteria();
		lCriteria.setUuid(aUuid);
		lCriteria.setEmail(aEmail);
		return validationMembreDao.findValidationMembreCriteria(lCriteria);
	}
}
